# -*- coding: utf-8 -*-
"""
__mktime__ = '2019/4/14'
__author__ = 'Just'
__filename__ = 'base'
"""
from flask import request
from wtforms import Form
from app.libs.error_code import ParameterException


# FormBase  wtforms已里有BaseForm 避免引入错乱, 换名
class FormBase(Form):
    """API参数检验基类"""
    def __init__(self):
        data = request.get_json(silent=True)
        args = request.args.to_dict()
        print('post ', request.data)
        print('get ', request.args)
        super(FormBase, self).__init__(data=data, **args)

    def validate_for_api(self):
        """执行API参数检验"""
        valid = super(FormBase, self).validate()
        if not valid:
            print('error= ', self.errors)
            raise ParameterException(msg=self.errors)
        return self
